﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using Peter.Logic.Interfaces;
using System;

namespace Peter.Logic
{
    /// <summary>
    /// Invokes methods asynchronously
    /// </summary>
    public class MethodInvoker : IMethodInvoker
    {
        /// <summary>
        /// Invokes methods asynchronously
        /// </summary>
        /// <param name="method">Method to be called asynchronously</param>
        /// <param name="callback">Callback method</param>
        public void InvokeMethod(Action method, AsyncCallback callback)
        {
            method.BeginInvoke(callback, method);
        }

        /// <summary>
        /// Invokes methods asynchronously
        /// </summary>
        /// <typeparam name="T">Parameter for the asynch method</typeparam>
        /// <param name="method">Method to be called asynchronously</param>
        /// <param name="t">Parameter for the asynch method</param>
        /// <param name="callback">Callback method</param>
        public void InvokeMethod<T>(Action<T> method, T t, AsyncCallback callback)
        {
            method.BeginInvoke(t, callback, method);
        }

       /// <summary>
       /// Invokes methods asynchronously
       /// </summary>
       /// <typeparam name="T">Parameter for the asynch method</typeparam>
       /// <typeparam name="T2">Additional parameter.</typeparam>
       /// <param name="method">Method to be called asynchronously</param>
       /// <param name="t">Parameter for the asynch method</param>
       /// <param name="t2">Additional parameter.</param>
       /// <param name="callback">Callback method</param>
       public void InvokeMethod<T, T2> (Action<T, T2> method, T t, T2 t2, AsyncCallback callback)
        {
           method.BeginInvoke (t, t2, callback, method);
        }
    }
}
